package org.example.controller;
import com.github.pagehelper.PageInfo;
import org.example.entity.Course;
import org.example.service.CourseSerive;
import org.example.util.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("course")
public class CourseController {
    @Autowired
    private CourseSerive courseSerive;

    @GetMapping("{id}")
    public R getCourseById(@PathVariable("id") int id) {
        Course courseById = courseSerive.getCourseById(id);
        return R.ok(courseById);
    }

    @GetMapping("page")
    public R getCourse(Course course,
                       @RequestParam(required = false,defaultValue = "1") int page,
                       @RequestParam(required = false,defaultValue = "4")int size) {
        PageInfo<Course> courses = courseSerive.getCourses(course, page, size);
        return R.ok(courses);
    }
    @GetMapping("/{ids}/cour")
    public R selectCoursesById(@PathVariable("ids") int id){
        List<Course> courses = courseSerive.selectCoursesById(id);
        return R.ok(courses);
    }
//    分页模糊
    @GetMapping("page2")
    public R getCourses(Course course,
                        @RequestParam(required = false,defaultValue = "1") int page,
                        @RequestParam(required = false,defaultValue = "5") int size) {
        PageInfo<Course> coursesPage = courseSerive.getCoursesPage(course, page, size);
        return R.ok(coursesPage);
    }
    @GetMapping("/{id}/getcon")
    public R getConsultants(@PathVariable("id") int id){
        Course consultants = courseSerive.getConsultants(id);
        return R.ok(consultants);
    }
    @GetMapping("/{id}/tag")
    public R getTags(@PathVariable("id") int id){
        List<Course> consultantsTag = courseSerive.getConsultantsTag(id);
        return R.ok(consultantsTag);
    }
//    价格升序
    @GetMapping("asc")
    public R priceAsc(Course course,
                      @RequestParam(required = false,defaultValue = "1") int page,
                      @RequestParam(required = false,defaultValue = "10") int size){
        PageInfo<Course> coursePageInfo = courseSerive.priceAsc(course, page, size);
        return R.ok(coursePageInfo);
    }
//    价格降序
    @GetMapping("desc")
    public R priceDesc(Course course,
                       @RequestParam(required = false,defaultValue = "1") int page,
                       @RequestParam(required = false,defaultValue = "10") int size){
        PageInfo<Course> coursePageInfo = courseSerive.priceDesc(course, page, size);
        return R.ok(coursePageInfo);
    }
//    价格区间
    @GetMapping("qujian")
    public R priceQu(String priceRanges){
        List<Course> coursesByPriceRange = courseSerive.getCoursesByPriceRange(priceRanges);
        return R.ok(coursesByPriceRange);
    }
}
